/**
 * Created by zhaojm on 15/3/28.
 */
game.HubLayer = cc.Layer.extend({
    ctor: function () {
        this._super();

        var listener = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,       // true 为不向下传递
            onTouchBegan: this.onTouchBegan,
            onTouchMoved: this.onTouchMoved,
            //onTouchEnded: this.onTouchEnded,
            //onTouchCancel: this.onTouchCancel
        });
        this._touchListener = listener;
        cc.eventManager.addListener(listener, this);
    },

    onTouchBegan: function (touch, event) {
        return true;
    },
    onTouchMoved: function (touch, event) {
        var self = game.Globals.hubLayer;
        //cc.log('on touch moved');
        var winSize = cc.winSize;

        var ship = self.parent.getShip();
        if (ship) {
            var pos = touch.getDelta();
            var currentPos = ship.getPosition();
            var currentPos = cc.pAdd(currentPos, pos);
            var currentPos = cc.pClamp(currentPos, cc.p(0, 0), cc.p(winSize.width, winSize.height));
            ship.setPosition(currentPos);
        }
    }
});